//package com.mocha.nezha.graph;
//
//import cn.hutool.core.collection.CollectionUtil;
//import com.mocha.common.kits.MapKits;
//import com.mocha.nezha.vehicle.nezha.PoleVertex;
//import lombok.Getter;
//import org.apache.hugegraph.structure.graph.Edge;
//import org.apache.hugegraph.structure.graph.Vertex;
//import org.jgrapht.GraphPath;
//import org.jgrapht.alg.shortestpath.AllDirectedPaths;
//import org.jgrapht.graph.DefaultDirectedGraph;
//import org.jgrapht.graph.DefaultEdge;
//import org.jgrapht.traverse.DepthFirstIterator;
//
//import java.util.*;
//
///**
// * @author songkui
// * @since 2024/3/19 16:04
// */
//
//@Getter
//public class ParkPoleDirectedGraph {
//
//    private   DefaultDirectedGraph<PoleVertex, DefaultEdge> poleGraph = null;
//    private   Map<String, PoleVertex> poleMap = null;  //key PoleCode
//    private   String pakCode;
//
//    public ParkPoleDirectedGraph(){
//    }
//
//    public void initializeCameraGraph(String pid) throws Exception {
//        pakCode = pid;
//        poleGraph = new DefaultDirectedGraph<>(DefaultEdge.class);
//
//        List<Vertex> vertexList = HugeGraphClientManager.listAllVertex(pid);
//        List<Edge> edgeList = HugeGraphClientManager.listAllEdge(pid);
//        if (CollectionUtil.isEmpty(vertexList) || CollectionUtil.isEmpty(edgeList)) {
//            throw new Exception("Initialize camera graph  data is incomplete");
//        }
//
//        poleMap = new HashMap<>(MapKits.mapSize(vertexList.size()));
//        for (Vertex vertex : vertexList) {
//            PoleVertex cameraVertex = new PoleVertex(Optional.ofNullable(vertex.id()).map(String::valueOf).orElseThrow(() -> new Exception("Initialize camera graph vertex id is null")), (String) vertex.properties().get("pole_code"), (String) vertex.properties().get("pole_name"),false);
//            poleGraph.addVertex(cameraVertex);
//            poleMap.put(cameraVertex.getPoleCode(), cameraVertex);
//        }
//
//        for (Edge edge : edgeList) {
//            PoleVertex source = poleMap.get(edge.sourceId());
//            PoleVertex target = poleMap.get(edge.targetId());
//            if (null == source || null == target) {
//                throw new Exception("Initialize camera graph  edge  source  or target is null");
//            }
//
//            poleGraph.addEdge(source, target);
//        }
//
//        Set<PoleVertex> vertexSet = poleGraph.vertexSet();
//        if (CollectionUtil.isEmpty(vertexSet)){
//            throw new Exception("Initialize camera graph vertexSet  is null");
//        }
//
//        for (PoleVertex vertex : vertexSet){
//            vertex.setFork(isFork(vertex));
//        }
//
//    }
//
//
//    public  boolean isFork(PoleVertex vertex){
//        Set<DefaultEdge> edgeSet = poleGraph.outgoingEdgesOf(vertex);
//        return CollectionUtil.isEmpty(edgeSet) || edgeSet.size() < 3 ? false : true;
//    }
//
//    public PoleVertex getNext(PoleVertex vertex){
//        Set<DefaultEdge> edgeSet = poleGraph.outgoingEdgesOf(vertex);
//        DefaultEdge x = edgeSet.stream().iterator().next();
//
//        return null;
//    }
//
//
//    public List<PoleVertex> getAfter(PoleVertex v) {
//        if (v == null || !poleGraph.containsVertex(v)) {
//            return null;
//        }
//        List<PoleVertex> resultList = new ArrayList<>();
//        DepthFirstIterator<PoleVertex, DefaultEdge> iterator = new DepthFirstIterator<>(poleGraph, v);
//        while (iterator.hasNext()) {
//            PoleVertex next = iterator.next();
//            if (next == v) {
//                continue;
//            }
//            resultList.add(next);
//        }
//
//        return resultList;
//    }
//
//
//    private List<List<PoleVertex>> findAllPaths(PoleVertex start, PoleVertex end) {
//        List<List<PoleVertex>> paths = new ArrayList<>();
//        AllDirectedPaths<PoleVertex, DefaultEdge> alg = new AllDirectedPaths<>(poleGraph);
//        List<GraphPath<PoleVertex, DefaultEdge>> allGraphPaths = alg.getAllPaths(start, end, true, 100);
//
//        for (GraphPath<PoleVertex, DefaultEdge> graphPath : allGraphPaths) {
//            List<PoleVertex> pathNodes = new ArrayList<>();
//            for (PoleVertex node : graphPath.getVertexList()) {
//                pathNodes.add(node);
//            }
//            paths.add(pathNodes);
//        }
//
//        return paths;
//    }
//
//
//
////    public void tp(){
////        JGraphXAdapter<String, DefaultEdge> graphAdapter = new JGraphXAdapter<PoleVertex, DefaultEdge>(cameraGraph);
////        mxIGraphLayout layout = new mxCircleLayout(graphAdapter);
////        layout.execute(graphAdapter.getDefaultParent());
////
////        BufferedImage image =
////                mxCellRenderer.createBufferedImage(graphAdapter, null, 2, Color.WHITE, true, null);
////        File imgFile = new File("D:/graph.png");
////        ImageIO.write(image, "PNG", imgFile);
////
////
////    }
//
//
//}
